<script setup>
import { ref, reactive, watch, computed, nextTick, getCurrentInstance } from 'vue'
import SelectPopup from "@/components/selectPopup.vue";
import SelectStore from "@/components/selectStore.vue";
import SelectPark from "@/components/selectPark.vue";
import { uploadUrl, getDeptByParent, getCheckType, getStoreList, getCheckInfoList, createStoreCheckList, modifyStoreCheckList, updateUserSign, delphoto } from "@/api";
import { getaqjcGcomptypeCon, getParamsGcompanyList, getGCompanyDetail, addAqjcGcompanyRecord, updateAqjcGcompanyRecord } from '@/api/park'
import Uploader from "@/components/uploader.vue";
import { host, baseUrl } from "@/utils/config";
import { onLoad } from "@dcloudio/uni-app";
import Signature from "@/components/signature.vue";

const userInfo = uni.getStorageSync('userInfo')
const dict = reactive({})
const formData = ref(null)
const deptName = ref(null)
const pageData = reactive({
  activeCollapse: 1,
  formData: {
    deptId: null,
    compName: null,
    compScale: null,
    compType: null,
    compTypeIds: [],
    compCode: null,
    compImage: [],
    compNum: null,
    compAddress: null,
    compPerson: null,
    gardenPhone: null,
    safePerson: null,
    safePhone: null,
    lon: null,
    lat: null,
    remark: null,
    recorddtls: [
    ]
  },
  checkInfoList: []
})
const formRule = {
  compName: [
    {
      required: true,
      message: '请选择企业'
    }
  ],
  checktypeId: [
    {
      required: true,
      message: '请选择检查类型'
    }
  ],
  okSign1: [
    {
      required: true,
      message: '请签字'
    }
  ],
  okSign2: [
    {
      required: true,
      message: '请签字'
    }
  ],
  okSign3: [
    {
      required: true,
      message: '请签字'
    }
  ],
  todoSign1: [
    {
      required: true,
      message: '请签字'
    }
  ],
  todoSign2: [
    {
      required: true,
      message: '请签字'
    }
  ],
  todoSign3: [
    {
      required: true,
      message: '请签字'
    }
  ],
  nookSign1: [
    {
      required: true,
      message: '请签字'
    }
  ],
  nookSign2: [
    {
      required: true,
      message: '请签字'
    }
  ],
  nookSign3: [
    {
      required: true,
      message: '请签字'
    }
  ]
}
const placeholder = reactive({
  compNamePh: '请输入企业查询',
  checkinfoId: '请先选择检查类型'
})
const remoteParams = reactive({
  checkType: {
    api: getCheckType,
    params: {
      deptId: userInfo.dept.deptId
    },
    field: {
      text: 'typename',
      value: 'id'
    }
  },
  checkInfo: {
    api: getCheckInfoList,
    params: {
      typeid: ''
    },
    field: {
      text: 'content',
      value: 'id'
    }
  },
  enterprise: {
    api: getParamsGcompanyList,
    params: {
      compName: ''
    },
    field: {
      text: 'compName',
      value: 'id'
    }
  }
})

/* watch(
    () => pageData.formData.xqid,
    (nv, ov) => {
      console.log(nv, ov)
      remoteParams.store.params.xqid = nv
      nv ? placeholder.compNamePh = '请选择场所' : placeholder.compNamePh = '请先选择所属管辖'
    },
    {
      deep: true
    }
) */
watch(
    () => pageData.formData.checktypeId,
    (nv, ov) => {
      if (pageData.formData.id || nv === ov) return
      remoteParams.checkInfo.params.typeid = nv
      nv ? placeholder.checkinfoId = '请选择检查内容' : placeholder.checkinfoId = '请先选择检查类型'
      getCheckInfoList(remoteParams.checkInfo.params).then(res => {
        pageData.checkInfoList = res.data.filter(item => item.delFlag === 0).map(item => {
          return {
            value: item.id,
            text: item.content
          }
        })
        pageData.formData.recorddtls = res.data.filter(item => item.delFlag === 0).map(item => {
          return {
            checkinfoId: item.id,
            checkinfo: item.content,
            isOk: 1,
            // status: 1,
            checkPhotos: [],
            rectifyPhotos: [],
            placeholder: item.content,
            content: item.zgjy,
            egPic: item.egPic,
          }
        })
      })
    },
    {
      deep: true
    }
)
watch(
    () => pageData.formData.compName,
    (nv, ov) => {
      remoteParams.enterprise.params.compName = nv
    },
    {
      deep: true
    }
)
watch(
    () => pageData.formData.recorddtls,
    (nv, ov) => {
      if (isSubmit.value) return
      if (nv.some(item => item.status === 0)) {
        getFormStatus.value = 2
        pageData.formData.status = 2
        return
      }
      if (nv.some(item => (!item.id && item.isOk === 0) || (item.isOk === 0 && pageData.formData.status === 1))) {
        getFormStatus.value = 0
        pageData.formData.status = 0
        return
      }
      getFormStatus.value = 1
      pageData.formData.status = 1
    },
    {
      deep: true
    }
)

const getFormStatus = ref(1)

const isSubmit = ref(false)

const loadingBtn = ref(false)
const submit = () => {
  // console.log('pageData.formData', pageData.formData)
  // return
  formData.value.validate().then(({ valid, errors }) => {
    if (valid) {
      isSubmit.value = true
      pageData.formData.imgList = [
        ...pageData.formData.signboard || [],
        ...pageData.formData.license || [],
      ]
      pageData.formData.id = detailId
      for (let i = 0; i < pageData.formData.recorddtls.length; i++) {
        // if(pageData.formData.recorddtls[i].isOk1 === 0 && pageData.formData.recorddtls[i].isOk === 0 && pageData.formData.recorddtls[i].id) {
        //   pageData.formData.status = 2
        // }
        // if(pageData.formData.recorddtls[i].isOk1 === 1 && pageData.formData.recorddtls[i].isOk === 0 && pageData.formData.recorddtls[i].id) {
        //   pageData.formData.status = 1
        // }
        pageData.formData.recorddtls[i].imgList = []
        pageData.formData.recorddtls[i].imgList = [
          ...pageData.formData.recorddtls[i].checkPhotos,
          ...pageData.formData.recorddtls[i].rectifyPhotos
        ]
        for (let j = 0; j < pageData.formData.recorddtls[i].imgList.length; j++) {
          const photoItem = pageData.formData.recorddtls[i].imgList[j]
          photoItem.gtype = photoItem.type
        }
      }
      // console.log('提交pagedata', pageData.formData)
      // return
      loadingBtn.value = true
      let api
      let msg = ''
      if (pageData.formData.id) {
        api = updateAqjcGcompanyRecord
        msg = '更新成功！'
      } else {
        api = addAqjcGcompanyRecord
        msg = '新增成功！'
      }
      api(pageData.formData).then(res => {
        // console.log('create', res)
        if((!userInfo.signUrl && pageData.formData.okSign1) || (userInfo.signUrl && userInfo.signUrl !== pageData.formData.okSign1)) {
          const params = {
            userId: userInfo.userId,
            signUrl: pageData.formData.okSign1
          }
          updateUserSign(params)
        }
        uni.showToast({
          title: msg
        })
        isSubmit.value = false
        uni.navigateBack()
      }).catch(err => {
        loadingBtn.value = false
      })
    }
    else {
      console.log('error submit!!', errors)
      isSubmit.value = false
      uni.showToast({
        title: errors[0].message,
        icon: 'none'
      })
    }
  })
}
const getLocation = () => {
  uni.getLocation({
    type: 'gcj02',
    success: function (res) {
      console.log('当前位置的经度：' + res.longitude)
      console.log('当前位置的纬度：' + res.latitude)
      pageData.formData.lon = res.longitude
      pageData.formData.lat = res.latitude
    },
    fail: function (err) {
      console.log('位置error', err)
    }
  })
}
/* 涉及风险种类下拉 */
const getcomptype = async() => {
  await getaqjcGcomptypeCon({compId: pageData.formData.companyId}).then(res => {
    pageData.aqjcGcomptypeData = res.data
  })
}
const pathChange = (e) => {
  deptName.value = e.map(item => item.text).toString()
  pageData.formData.deptId = e[e.length-1].value
  pageData.formData.deptName = e[e.length-1].text
}
const changeStore = (store) => {
  pageData.formData.deptId = store.deptId
  pageData.formData.deptName = store.deptName
  pageData.formData.compName = store.compName
  deptName.value = pageData.formData.deptName
  pageData.formData.compAddress = store.compAddress
  pageData.formData.compScale = store.compScale
  pageData.formData.compCode = store.compCode
  pageData.formData.compType = store.compType
  pageData.formData.companyId = store.id
  pageData.formData.compImage = store.compImage ? [{url:host+store.compImage}] :''
  pageData.formData.compTypeIds = store.compTypeIds ? store.compTypeIds.map(str => parseInt(str)) : []
  pageData.formData.compNum = store.compNum || 1
  pageData.formData.gardenPhone = store.gardenPhone
  pageData.formData.compPerson = store.compPerson
  pageData.formData.safePerson = store.safePerson
  pageData.formData.safePhone = store.safePhone
  pageData.formData.lon = store.lon
  pageData.formData.lat = store.lat
  pageData.formData.remark = store.remark
  getcomptype()
  if(store.checktypeId) {
    let checkTypeData = []
    remoteParams.checkType.api(remoteParams.checkType.params).then(res => {
      checkTypeData = res[remoteParams.checkType.resField || 'data'].map(item => {
        return {
          text: item[remoteParams.checkType.field.text],
          value: item[remoteParams.checkType.field.value]
        }
      })
      pageData.formData.checktypeId = store.checktypeId
      const index = checkTypeData.findIndex(item => item.value === store.checktypeId)
      pageData.formData.typename = checkTypeData[index].text
    })
  }
  // console.log('lonlat', pageData.formData.lon, pageData.formData.lat)
  if (!pageData.formData.lon || !pageData.formData.lat) {
    getLocation()
  }
  /* for(let i = 0; i < store.photoList.length; i++) {
    const imgItem = store.photoList[i]
    if (!imgItem.imgUrl) continue
    const tmpArr = imgItem.imgUrl.split('/')
    imgItem.name = tmpArr[tmpArr.length - 1]
    const tmpArr1 = imgItem.name.split('.')
    imgItem.extname = tmpArr1[tmpArr1.length - 1]
    imgItem.url = host + imgItem.imgUrl
    console.log('imgItem', imgItem)
    if (store.photoList[i].type === 1) {
      pageData.formData.signboard = [imgItem]
    }
    if (store.photoList[i].type === 2) {
      pageData.formData.license = [imgItem]
    }
  } */
  // nextTick(() => {
  //   pageData.formData.signboard = signboard
  //   pageData.formData.license = license
  //   console.log('form', pageData.formData)
  // })
}

const changeDtlStatus = (v, item) => {
  item.status = v
}

const addCheckItem = () => {
  pageData.formData.recorddtls = [
      ...pageData.formData.recorddtls,
      ...[
        {
          checkinfoId: '',
          isOk: 1,
          // status: 1,
          checkPhotos: [],
          rectifyPhotos: []
        }
      ]
  ]
}
const minusCheckItem = (index) => {
  pageData.formData.recorddtls.splice(index, 1)
}
const confirmSign = (data, type) => {
  console.log('data', data)
  if (data === '') {
    return false
  }
  uni.uploadFile({
    url: uploadUrl, //上传图片的后端接口
    filePath: data,
    name: 'file',
    success: res => {
      pageData.formData[type] = JSON.parse(res.data).fileName
    }
  })
  // pageData.formData[type] = data
}

const clearSign = (type) => {
  pageData.formData[type] = ''
}
const detailId = ref('')
const isContinue = ref(false)
const loading = ref(false)

onLoad(async (options) => {
  if(options.id) {
    detailId.value = options.id
    const res = await getCheckType({})
    await getDetail(detailId.value, options.isShare)
    return
  }
  if(options.isContinue) {
    isContinue.value = true
    uni.getStorage({
      key: 'createInspectCatch',
      success: (res) => {
        console.log('createInspectCatch', res.data)
        pageData.formData = res.data
      }
    })
  }
  pageData.formData.okSign1 = userInfo.signUrl
  pageData.formData.todoSign1 = userInfo.signUrl
  pageData.formData.nookSign1 = userInfo.signUrl
  // if(options.name && options.xqid && options.xqname) {
  //   pageData.formData.xqid = options.xqid
  //   pageData.formData.xqname = options.xqname
  //   pageData.formData.csname = options.name
  // }
  
})

let docStatus = 0

const getDetail = async(id, isShare) => {
  console.log(id)
  // return
  loading.value = true
  const api = getGCompanyDetail
  await api(id).then(res => {
    deptName.value = pageData.formData.deptName
    // console.log('pageData.formData.status', pageData.formData.status)
    if ([0, 3].includes(res.data.status)) {
      res.data.okSign2 = res.data.todoSign2
      res.data.okSign3 = res.data.todoSign3
      res.data.nookSign2 = res.data.todoSign2
      res.data.nookSign3 = res.data.todoSign3
    }
    pageData.formData = {...res.data,...res.data.aqjcGardenCompany}
    pageData.formData.compImage = pageData.formData.compImage ? [{url:host+pageData.formData.compImage}] :''
    pageData.formData.compTypeIds = pageData.formData.compTypeIds ? pageData.formData.compTypeIds.map(str => parseInt(str)) : []
        
    getcomptype()
    console.log('pageData.formData', pageData.formData)
    if (!pageData.formData.okSign1) {
      pageData.formData.okSign1 = userInfo.signUrl
    }
    if (!pageData.formData.todoSign1) {
      pageData.formData.todoSign1 = userInfo.signUrl
    }
    if (!pageData.formData.nookSign1) {
      pageData.formData.nookSign1 = userInfo.signUrl
    }
    docStatus = pageData.formData.status

    console.log('res.data', res.data)
    console.log('formData', pageData.formData)
    for(let i = 0; i < pageData.formData.imgList?.length; i++) {
      const imgItem = pageData.formData.imgList[i]
      if (!imgItem.imgUrl) continue
      const tmpArr = imgItem.imgUrl.split('/')
      imgItem.name = tmpArr[tmpArr.length - 1]
      const tmpArr1 = imgItem.name.split('.')
      imgItem.extname = tmpArr1[tmpArr1.length - 1]
      imgItem.url = host + imgItem.imgUrl
      if (pageData.formData.imgList[i].type === 1) {
        pageData.formData.signboard = [imgItem]
      }
      if (pageData.formData.imgList[i].type === 2) {
        pageData.formData.license = [imgItem]
      }
    }
    for (let i = 0; i < pageData.formData.recorddtls.length; i++) {
      /* if ([0, 2, 3].includes(pageData.formData.recorddtls[i].status)) {
        pageData.formData.recorddtls[i].isOk1 = 0
      } else {
        pageData.formData.recorddtls[i].isOk1 = 1
      } */
      if(pageData.formData.recorddtls[i].isOk == 0 && !pageData.formData.recorddtls[i].status){
        pageData.formData.recorddtls[i].status = 1
      }
      pageData.formData.recorddtls[i].checkPhotos = []
      pageData.formData.recorddtls[i].rectifyPhotos = []
      for (let j = 0; j < pageData.formData.recorddtls[i].imgList.length; j++) {
        const photoItem = pageData.formData.recorddtls[i].imgList[j]
        if (!photoItem.imgUrl) continue
        const tmpArr = photoItem.imgUrl.split('/')
        photoItem.name = tmpArr[tmpArr.length - 1]
        const tmpArr1 = photoItem.name.split('.')
        photoItem.extname = tmpArr1[tmpArr1.length - 1]
        photoItem.url = host + photoItem.imgUrl
        if (photoItem.gtype === 3) {
          pageData.formData.recorddtls[i].checkPhotos.push(photoItem)
        }
        if (photoItem.gtype === 4) {
          pageData.formData.recorddtls[i].rectifyPhotos.push(photoItem)
        }
      }
    }
    const params = {
      typeid: pageData.formData.checktypeId
    }
    getCheckInfoList(params).then(res => {
      nextTick(() => {
        pageData.checkInfoList = res.data.map(item => {
          return {
            value: item.id,
            text: item.content
          }
        })
        loading.value = false
      })
    })
    console.log('formData1', pageData.formData)
  })
}

const fullscreenSign = ref(null)
const isFullScreen = ref(false)
const currentSign = ref('')
const closeFullScreen = () => {
  isFullScreen.value = false
}
const setFullScreen = (v, field) => {
  isFullScreen.value = true
  currentSign.value = field
}
const signWidth = ref(null)
const signHeight = ref(null)
const confirmSignFs = (canvas, data, type) => {
  uni.getImageInfo({
    src: data,
    success: function(res) {
      signWidth.value = res.width
      signHeight.value = res.height
      console.log('wh', signWidth.value, signHeight.value)
      const ctx = uni.createCanvasContext('fullscreenCanvas')
      console.log('ctx', ctx)
      ctx.translate(0, signWidth.value)
      ctx.rotate((270 * Math.PI) / 180)
      ctx.drawImage(data, 0, 0, signWidth.value, signHeight.value)
      // ctx.drawImage(data, 0, 0, width, height)
      ctx.draw()
      setTimeout(() => {
        uni.canvasToTempFilePath({
          canvasId: 'fullscreenCanvas',
          success: function(res) {
            // 在H5平台下，tempFilePath 为 base64
            // console.log('resssssssss', res.tempFilePath)
            uni.uploadFile({
              url: uploadUrl, //上传图片的后端接口
              filePath: res.tempFilePath,
              name: 'file',
              success: res => {
                // console.log('rrrrrrrrr', res)
                pageData.formData[type] = JSON.parse(res.data).fileName
                isFullScreen.value = false
              }
            })
            pageData.formData[type] = data
          },
          fail: function (err) {
            console.log('errrrrrrr', err)
          }
        })
      }, 200)
    },
    fail: function(res) {
      console.log('errr', res)
    }
  })
}

Object.assign(dict, uni.getStorageSync('dict'))

const hiddenOk = ref(1)


const uploadDel = (e) => {
  console.log('eeeeee', e)
  if (!e.id) return
  const params = {
    id: e.id
  }
  delphoto(params)
}

const save = () => {
  uni.setStorage({
    key: 'createInspectCatch',
    data: pageData.formData,
    success: () => {
      uni.showToast({
        title: '暂存成功！',
        icon: 'success'
      })
    }
  })
}
const changeIsOk1 = (v, item) => {
  console.log('item', v, item)
  item.status = v ? 1 : 0
}

const showEg = ref(false)
const egInfo = ref({})
const handlePopupEg = (item) => {
  console.log('item', item)
  egInfo.value = item
  showEg.value = true
}
</script>

<template>
  <nut-loading-page :loading="loading" />
  <nut-form :model-value="pageData.formData" ref="formData" :rules="formRule">
    <nut-collapse v-model="pageData.activeCollapse" :accordion="true">
      <nut-collapse-item title="基础信息" :name="1">
        <nut-form-item label="企业名称" prop="compName" label-width="70">
          <nut-input v-if="pageData.formData.id" v-model="pageData.formData.compName" placeholder="" readonly/>
          <select-store v-else v-model="pageData.formData.compName" type="enterprise" :placeholder="placeholder.compNamePh" :remote-params="remoteParams.enterprise" @change="changeStore"></select-store>
        </nut-form-item>
        <view v-show="deptName || pageData.formData.id">
          <nut-form-item label="所属园区" prop="deptName" label-width="70">
            <nut-input v-model="pageData.formData.deptName" placeholder="" readonly/>
           </nut-form-item> 
           <nut-form-item label="企业规模" prop="compScale">
              <select-popup v-model="pageData.formData.compScale" disabled :echo="pageData.formData.dictLabel" :columns="dict.sys_comp_scale"></select-popup>
          </nut-form-item>
          <nut-form-item label="企业类型" prop="compType">
              <select-popup v-model="pageData.formData.compType" disabled :echo="pageData.formData.dictLabel" :columns="dict.sys_comp_type"></select-popup>
          </nut-form-item>
          <nut-form-item label="涉及风险种类" prop="compTypeIds">
            <nut-checkboxgroup v-model="pageData.formData.compTypeIds" disabled>
              <nut-checkbox v-for="(item,index) in pageData.aqjcGcomptypeData" :key="item.typeId" :label="item.typeId">{{item.typeName}}</nut-checkbox>
            </nut-checkboxgroup>
          </nut-form-item>
          <nut-form-item label="统一信用编码" prop="compCode">
              <nut-input v-model="pageData.formData.compCode" placeholder="请输入统一信用编码" readonly/>
          </nut-form-item>
          <nut-form-item label="企业图片" prop="compImage">
              <uploader v-model="pageData.formData.compImage" :url="uploadUrl" :del="false" return-type="object" :limit="1"></uploader>
          </nut-form-item>
          <nut-form-item label="企业人数" prop="compNum">
            <nut-input v-model="pageData.formData.compNum" readonly/>
          </nut-form-item>
          <nut-form-item label="地址" prop="compAddress">
            <text style="color:#000">{{pageData.formData.compAddress}}</text>
              <!-- <nut-input v-model="pageData.formData.compAddress" placeholder="请输入地址" readonly/> -->
          </nut-form-item>
          <nut-form-item label="负责人" prop="compPerson">
              <nut-input v-model="pageData.formData.compPerson" placeholder="请输入负责人" readonly/>
          </nut-form-item>
          <nut-form-item label="负责人联系方式" prop="gardenPhone">
              <nut-input v-model="pageData.formData.gardenPhone" placeholder="请输入负责人联系方式" readonly/>
          </nut-form-item>
          <nut-form-item label="安全人员" prop="safePerson">
              <nut-input v-model="pageData.formData.safePerson" placeholder="请输入安全人员" readonly/>
          </nut-form-item>
          <nut-form-item label="安全人员联系方式" prop="safePhone">
              <nut-input v-model="pageData.formData.safePhone" placeholder="请输入安全人员联系方式" readonly/>
          </nut-form-item>
          <nut-form-item label="备注" prop="remark">
              <nut-input v-model="pageData.formData.remark" placeholder="" readonly/>
          </nut-form-item>
        </view>
      </nut-collapse-item>
      <nut-collapse-item title="检查内容" :name="2">
        <nut-form-item v-if="pageData.formData.id" label="是否隐藏合格项" prop="hiddenOk" label-width="140">
          <nut-switch v-model="hiddenOk" :active-value="1" :inactive-value="0" active-color="green"/>
        </nut-form-item>
        <nut-form-item label="检查类型" prop="checktypeId" label-width="70" :rules="[
                {
                  required: true,
                  message: '请选择检查类型'
                }
            ]">
          <select-popup v-model="pageData.formData.checktypeId" :echo="pageData.formData.typename" is-remote :remote-params="remoteParams.checkType"></select-popup>
        </nut-form-item>
        <nut-row v-for="(item, index) in pageData.formData.recorddtls" :key="index">
          <nut-divider v-if="item.isOk === 0" dashed />
          <nut-col v-if="!pageData.formData.id || item.isOk !== 1 || !hiddenOk" :span="24" style="border-top: 1px solid #aaa;">
            <nut-form-item v-if="item.checkinfoId && pageData.checkInfoList.length" :label="'检查内容'+Number(index+1)" :prop="'recorddtls.' + index + '.checkinfoId'" label-width="90" :rules="[
                {
                  required: true,
                  message: '请选择检查内容'
                }
            ]">
              <select-popup v-model="item.checkinfoId" :columns="pageData.checkInfoList" :placeholder="item.checkinfo" :echo="item.checkinfo" :disabled="!pageData.formData.checktypeId"></select-popup>
            </nut-form-item>
            <nut-form-item :prop="'recorddtls.' + index + '.checkPhotos'" label-width="70">
              <template #label>
                <view>检查照片</view>
                <view v-if="item.egPic" class="eg" @click="handlePopupEg(item)"><nut-icon name="tips" custom-color="#fa2c19"></nut-icon></view>
              </template>
              <uploader v-model="item.checkPhotos" :url="uploadUrl" type="3" @uploadDel="uploadDel"></uploader>
            </nut-form-item>
            <nut-form-item label="是否合格" prop="isOk">
              <template v-if="pageData.formData.id">
                <nut-tag v-if="item.isOk == 1" type="success">合格</nut-tag>
                <nut-tag v-else type="danger">不合格</nut-tag>
              </template>
              <nut-switch v-model="item.isOk" v-else :active-value="1" :inactive-value="0" active-color="green"/>
            </nut-form-item>
            <!-- <nut-divider v-if="item.isOk === 0" dashed /> -->
            <nut-form-item v-if="item.isOk === 0" label="整改建议" :prop="'recorddtls.' + index + '.content'" label-width="70">
              <view style="color: #000;">{{ item.content }}</view>
              <!-- <nut-input v-model="item.content" placeholder="请输入文本" /> -->
            </nut-form-item>
            <nut-form-item v-if="item.isOk === 0 && item.id" label="整改照片" :prop="'recorddtls.' + index + '.rectifyPhotos'" label-width="70">
              <uploader v-model="item.rectifyPhotos" :url="uploadUrl" type="4" @uploadDel="uploadDel"></uploader>
            </nut-form-item>
            <nut-form-item v-if="item.isOk === 0 && item.id" label="是否合格" prop="status" label-width="70">
              <nut-switch v-model="item.status" :active-value="1" :inactive-value="0" @change="(v) => changeIsOk1(v, item)" active-color="green"/>
            </nut-form-item>
          </nut-col>
          <nut-col v-if="!pageData.formData.id || item.isOk === 0 || !hiddenOk" :span="24">
            <view style="height: 1px;background: #eee;"></view>
          </nut-col>
        </nut-row>
      </nut-collapse-item>
      <nut-collapse-item v-if="getFormStatus === 1 && !userInfo.roleIds.includes(106)" title="合格签字" :name="3">
        <nut-form-item label="检查人员签字(合格)" prop="okSign1" label-width="70">
          <view v-if="pageData.formData.okSign1">
            <image :src="host + pageData.formData.okSign1" style="width: 260px;height: 150px;" />
            <nut-button size="mini" type="primary" @click="clearSign('okSign1')">重签</nut-button>
          </view>
          <signature v-else :field="'okSign1'" @confirm="confirmSign" @clear="clearSign" @set-full-screen="(v) => setFullScreen(v, 'okSign1')"></signature>
        </nut-form-item>
        <nut-form-item label="场所人员签字(合格)" prop="okSign2" label-width="70">
          <view v-if="pageData.formData.okSign2">
            <image :src="host + pageData.formData.okSign2" style="width: 260px;height: 150px;" />
            <nut-button size="mini" type="primary" @click="clearSign('okSign2')">重签</nut-button>
          </view>
          <signature v-else :field="'okSign2'" @confirm="confirmSign" @clear="clearSign" @set-full-screen="(v) => setFullScreen(v, 'okSign2')"></signature>
        </nut-form-item>
        <nut-form-item label="主管部门签字(合格)" prop="okSign3" label-width="70">
          <view v-if="pageData.formData.okSign3">
            <image :src="host + pageData.formData.okSign3" style="width: 260px;height: 150px;" />
            <nut-button size="mini" type="primary" @click="clearSign('okSign3')">重签</nut-button>
          </view>
          <signature v-else :field="'okSign3'" @confirm="confirmSign" @clear="clearSign" @set-full-screen="(v) => setFullScreen(v, 'okSign3')"></signature>
        </nut-form-item>
      </nut-collapse-item>
      <nut-collapse-item v-if="getFormStatus === 0 && !userInfo.roleIds.includes(106)" title="整改签字" :name="3">
        <nut-form-item label="检查人员签字(整改)" prop="todoSign1" label-width="70">
          <view v-if="pageData.formData.todoSign1">
            <image :src="host + pageData.formData.todoSign1" style="width: 260px;height: 150px;" />
            <nut-button size="mini" type="primary" @click="clearSign('todoSign1')">重签</nut-button>
          </view>
          <signature v-else :field="'todoSign1'" @confirm="confirmSign" @clear="clearSign" @set-full-screen="(v) => setFullScreen(v, 'todoSign1')"></signature>
        </nut-form-item>
        <nut-form-item label="场所人员签字(整改)" prop="todoSign2" label-width="70">
          <view v-if="pageData.formData.todoSign2">
            <image :src="host + pageData.formData.todoSign2" style="width: 260px;height: 150px;" />
            <nut-button size="mini" type="primary" @click="clearSign('todoSign2')">重签</nut-button>
          </view>
          <signature v-else :field="'todoSign2'" @confirm="confirmSign" @clear="clearSign" @set-full-screen="(v) => setFullScreen(v, 'todoSign2')"></signature>
        </nut-form-item>
        <nut-form-item label="主管部门签字(整改)" prop="todoSign3" label-width="70">
          <view v-if="pageData.formData.todoSign3">
            <image :src="host + pageData.formData.todoSign3" style="width: 260px;height: 150px;" />
            <nut-button size="mini" type="primary" @click="clearSign('todoSign3')">重签</nut-button>
          </view>
          <signature v-else :field="'todoSign3'" @confirm="confirmSign" @clear="clearSign" @set-full-screen="(v) => setFullScreen(v, 'todoSign3')"></signature>
        </nut-form-item>
      </nut-collapse-item>
      <nut-collapse-item v-if="getFormStatus === 2 && !userInfo.roleIds.includes(106)" title="不合格签字" :name="3">
        <nut-form-item label="检查人员签字(不合格)" prop="nookSign1" label-width="70">
          <view v-if="pageData.formData.nookSign1">
            <image :src="host + pageData.formData.nookSign1" style="width: 260px;height: 150px;" />
            <nut-button size="mini" type="primary" @click="clearSign('nookSign1')">重签</nut-button>
          </view>
          <signature v-else :field="'nookSign1'" @confirm="confirmSign" @clear="clearSign" @set-full-screen="(v) => setFullScreen(v, 'nookSign1')"></signature>
        </nut-form-item>
        <nut-form-item label="场所人员签字(不合格)" prop="nookSign2" label-width="70">
          <view v-if="pageData.formData.nookSign2">
            <image :src="host + pageData.formData.nookSign2" style="width: 260px;height: 150px;" />
            <nut-button size="mini" type="primary" @click="clearSign('nookSign2')">重签</nut-button>
          </view>
          <signature v-else :field="'nookSign2'" @confirm="confirmSign" @clear="clearSign" @set-full-screen="(v) => setFullScreen(v, 'nookSign2')"></signature>
        </nut-form-item>
        <nut-form-item label="主管部门签字(不合格)" prop="nookSign3" label-width="70">
          <view v-if="pageData.formData.nookSign3">
            <image :src="host + pageData.formData.nookSign3" style="width: 260px;height: 150px;" />
            <nut-button size="mini" type="primary" @click="clearSign('nookSign3')">重签</nut-button>
          </view>
          <signature v-else :field="'nookSign3'" @confirm="confirmSign" @clear="clearSign" @set-full-screen="(v) => setFullScreen(v, 'nookSign3')"></signature>
        </nut-form-item>
      </nut-collapse-item>
    </nut-collapse>
  </nut-form>
  <nut-cell v-if="!userInfo.roleIds.includes(106)">
    <nut-row :gutter="20">
      <nut-col :span="12">
        <nut-button :loading="loadingBtn" type="success" block @click="submit">提交</nut-button>
      </nut-col>
      <nut-col :span="12">
        <nut-button :loading="loadingBtn" type="default" block @click="save">暂存</nut-button>
      </nut-col>
    </nut-row>
  </nut-cell>
  <view v-if="isFullScreen" class="fullscreen-sign">
    <view class="sign">
      <nut-signature
          ref="fullscreenSign"
          custom-class="fullscreenSign"
          @confirm="(canvas, data) => confirmSignFs(canvas, data, currentSign)"
          @clear="clearSign(currentSign)"
      />
      <canvas v-if="signWidth && signHeight" canvas-id="fullscreenCanvas" :style="`width:${signHeight}px; height:${signWidth}px;position: absolute;left: -9999px;`"></canvas>
    </view>
    <view class="btn">
      <nut-button type="primary" @click="closeFullScreen">关闭全屏</nut-button>
    </view>
  </view>
  <nut-popup position="bottom" v-model:visible="showEg">
    <view class="head-popup">图片示例</view>
    <view class="body-popup">
      <nut-form>
        <nut-form-item label="检查内容">
          {{ egInfo.content }}
        </nut-form-item>
        <nut-form-item label="示例图片">
          <image style="width: 200px; height: 200px;" :src="host + egInfo.egPic"></image>
        </nut-form-item>
      </nut-form>
    </view>
  </nut-popup>
  <nut-safe-area position="bottom" />
</template>

<style scoped lang="scss">
.row{width: 50%;}
.eg{padding: 10px 0 0;text-align: center}
.head-popup{padding: 20px 0 10px;text-align: center;font-size: 20px}
</style>
